/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lwjglbase;

import org.lwjgl.input.Keyboard;
import static org.lwjgl.util.glu.GLU.*;

/**
 *
 * @author andrew
 */
public class Camera {

    float x, y, z, xAng, yAng, dx, dy, dz;

    public Camera(float x, float y, float z, float xAng, float yAng) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.xAng = xAng;
        this.yAng = yAng;
        calcPoints(xAng, yAng);
    }
    private void calcPoints(float xa, float ya) {
        dx = Utils.cos(xa) * Utils.sin(ya);
        dy = Utils.cos(ya);
        dz = Utils.sin(xa) * Utils.sin(ya);
    }

    void look() {
        calcPoints(xAng, yAng);
        gluLookAt(x, y, z, x + dx, y + dy, z + dz, 0, 1, 0);
    }

    void move() {
        calcPoints(xAng, yAng);
        if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
            x += dx / 10;
            z += dz / 10;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
            x -= dx / 10;
            z -= dz / 10;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
            calcPoints(xAng - 90, yAng);
            x += dx / 10;
            z += dz / 10;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
            calcPoints(xAng + 90, yAng);
            x += dx / 10;
            z += dz / 10;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            y -= .05;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
            y += .05;
        }
    }

    void rotate(float dxa, float dya) {
        xAng += dxa / 5;
        yAng -= dya / 5;
        if(yAng > 179) {
            yAng = 179;
        }
        if(yAng < 1) {
            yAng = 1;
        }
    }
}
